/* $Header: typedefs.h,v 2.3 02/04/26 10:27:14 przybyls Exp $ */

/***********************************************************************/
/* INCLUDE FILE NAME:  typedefs.h                                      */
/* ==================                                                  */
/*                                                                     */
/* Author:  IQ Firmware Team                                           */
/*                                                                     */
/* COMMENT:  declare group wide typedefs                               */
/*                                                                     */
/***********************************************************************/

#ifndef TYPEDEFS_H
#define TYPEDEFS_H

/*-----begin change by wangwei-----------*/
#include <mccabe.h>
#include <pthread.h>
#include "test/globaldef.h"
/*-----end change------------------------*/
/*****************************/
/*   IFDEFS                  */
/*****************************/

        typedef unsigned char   BIT8;     /* This group of types is used for */
        typedef unsigned short  BIT16;    /* logical values, e.g. Display    */
        typedef unsigned int    BIT32;    /* Characters                      */

        typedef unsigned char   U_INT8;   /* This group of types is used for */
        typedef unsigned short  U_INT16;  /* unsigned integers               */
        typedef unsigned int    U_INT32;

        typedef char            INT8;      /* This group of types is used for */
        typedef short           INT16;     /* signed integers                 */
        typedef int             INT32;


        typedef enum { FRONT         = 0,   /* These typedefs are used for    */
                       BACK          = 1,   /* command and control system     */
                       NULL_POSITION = 2    /* common operations/variables    */
                     } POSITION;


        typedef enum { ON=1, OFF=0, SHUTDOWN=-1, FAIL=-2, TRANSITION=2, WAITING=3, WAITING2=4, STANDBY=5 } ON_OFF;

     /* typedef enum { TRUE=1, FALSE=0 } BOOLEAN; */

        typedef enum {
           DISABLED   = 0,
           ENABLED    = 1,
           COLD_START = 2
        } LAN_CTRL;


/* Signal defines and typedefs */

#define pSIGNAL1        &Signal1
#define pSIGNAL2        &Signal2
#define pSIGNALP        &SignalP

#define pCCOMP1         &Ccomp1
#define pCCOMP2         &Ccomp2
#define pTEST_PLOT      &Test_Plot

typedef struct
{
        U_INT32 lo;            /* LS 32-bits of 64-bit running bunch sum (d0) */
        U_INT32 hi;            /* MS 32-bits of 64-bit running bunch sum (d1) */

} BUNCH_SUM, *pBUNCH_SUM;

typedef struct
{
        U_INT32 output;           /* 32-bit signal result of bunching         */
        U_INT32 remainder;        /* 32-bit remainder result of bunching      */
} BUNCH_OUT32;

typedef struct
{
   INT32       *pfilt_table;
   BUNCH_SUM   filt_sum;
   BUNCH_OUT32 filt_out;
   U_INT16     ptr_filt;         /* pointer to last data point in  */
                                 /* boxcar data array              */
   U_INT16     size;             /* size of the boxcar             */
} SIG_FILTER, *pSIG_FILTER;

typedef enum
{
   NOT_PLOT_SIGNAL,
   SIZE_32_BIT,
   SIZE_16_BIT,
   SIZE_8_BIT,
   SIZE_16_BIT_SIGNED,
   SIZE_8_BIT_SIGNED

} DATA_SIZE;

/* typedefs for 6 byte data */

typedef struct
{
   INT32 hi_long;
   INT16 lo_word;

} DIG_DATA, *pDIG_DATA;

typedef struct
{
   INT16 hi_word;
   INT32 lo_long;

} INT48;

typedef union
{
   DIG_DATA data;
   INT48    num;

} DIG48;

typedef struct
{
   U_INT32 hi;
   U_INT32 lo;
} POINT_TYPE;

/* Diagnostics typedefs */
typedef enum
{
  PASSED = 0,
  FAILED = 1

} DIAG_RESULT;


/* Configuration typedefs */

typedef enum
{
  PP            = 0,
  COC           = 1,
  SS            = 2,
  PTV           = 3,
  MANUAL_PP     = 4,
  MANUAL_COC    = 5,
  MANUAL_SS     = 6,
  UNKNOWN_INLET = 7,
  NO_INLET      = 8,
  ACI           = 0x9,  /* ac's sim dist inlet; oem'ed by hp; no PC supp   */
  G_PTV         = 0xa,  /* gerstel's ptv  (pneumatic only) (no PC support)  */
  MANUAL_ACI    = 0xb,  /* ac's sim dist, packed mode (KLUGE!); no PC */
  CIS4          = 0xc,  /* gerstel's cooled injection system  rev 4 (thermal&pneu & PC) */
  SIMDIST       = 0x0d, /* real implementation of AC's sim dist inlet; w/ PC supp  */
  CIS3          = 0xe,  /* gerstel's ptv  (pneumatic only) (w/ PC support)  */
  JIB           = 0xf,  /* secondary standard iq manifold for manufacturing calibration */
  VOLATILES     = 0x10, /* volatile inlet for gas phase samples,  headspace, purge/trap interface */
  DFPD_DET_INL  = 0x11  /* inlet type used by EOS special that defines inlet thermal zone for Dual FPD */

} INLET_TYPE;

/* fake pneu to thinking that G_PTV is really a SS */
/*                  and that a ACI is really a COC */
#define SUPPORT_UNSUPPORTED_INLET_TYPES


typedef enum
{   INLET_MODULE = 1,
    DET_MODULE   = 2,
    AUX_MODULE   = 3
} MODULE_TYPE;

typedef enum
{   CAPPED       = 1,
    PLUMBED      = 2
} PNEU_PORT_STATE;

typedef enum
{
 PP_INLET, COC_INLET, SS_INLET, PTV_INLET, MAN_PP_INLET, MAN_COC_INLET, MAN_SS_INLET,
 SOME_AUX, UNKNOWN_TYPE, ACI_INLET, MAN_ACI_INLET, G_PTV_INLET, CIS4_INLET, SIMDIST_INLET,CIS3_INLET,
 VOLATILES_INLET
} COL_SOURCE_TYPE;

/* Detector types.  These are the detector pc-board 4-bit configuration word. */

typedef enum
{
  FID = 1, TCD = 2, ECD = 3, NPD = 4, FPD = 5, AIB = 6, uECD = 7, uECD2 = 8,
  DUAL_FPD = 9, LDID = 10, OEM_AIB = 13, OEM_FID = 14, NO_DET = 0x0f

  /* DUAL_FPD is EOS only */
  /* uECD used for 1st uECD signal p.c.b.                                                */
  /* uECD used for NuTronics version of uECD pneu_manifold ( has ONE pneu channel only)  */
  /* uECD2 used for uMachined version of uECD pneu_manifold ( has ONE pneu channel only) */
  /*                                                                                     */
  /* Operable uECD pneu/signal combinations:  Comments                                   */
  /*       Pneu_Manifold    Signal_P.C.B.     ----------------------------------------   */
  /*       -------------    --------------    ----------------------------------------   */
  /*          ECD              uECD1          Pneu = 2 Nutronic pres_across_frit ch's    */
  /*         uECD              uECD1          Pneu = 1 Nutronuc pres_across_frit ch.     */
  /*         uECD2             uECD1          Pneu = 1 uMacined pres_across_frit ch.     */

} DET_TYPE;

/* Detector types.  These are the detector manifold pc-board EEPROM 16-bit type word. */

#define EPC_DET_BIT 0x10

typedef enum
{
  MAN_FID   = FID,          MAN_TCD = TCD,           MAN_ECD = ECD,
  MAN_NPD   = NPD,          MAN_FPD = FPD,
  EPC_FID   = (int)FID   | EPC_DET_BIT, EPC_TCD  = (int)TCD  | EPC_DET_BIT, EPC_ECD  = (int)ECD     | EPC_DET_BIT,
  EPC_NPD   = (int)NPD   | EPC_DET_BIT, EPC_FPD  = (int)FPD  | EPC_DET_BIT, EPC_uECD = (int)uECD    | EPC_DET_BIT,
  EPC_uECD2 = (int)uECD2 | EPC_DET_BIT, EPC_LDID = (int)LDID | EPC_DET_BIT, EPC_OEM  = (int)OEM_AIB | EPC_DET_BIT

} EEPROM_DET_TYPE;

typedef enum
{
  NOT_USED      = 0,
  PRES          = 1,
  FLOW          = 2
} OEM_GAS_STATUS;


/* Zone types */

typedef enum
{
  NO_ZONE = 0, MISSING_SENSOR = 1, INVALID_HEATER = 2, ZONE_PRESENT = 3

} ZONE_PRESENCE;

typedef enum
{
  VLV_BOX = 0, UNKNOWN_AUX = 1, MSD_AUX = 2, AED_AUX = 3,
  NO_AUX = 4, CRYO_TRAP = 5, NIC_CAT = 6, FPD_AUX = 7, MAX_AUX_TYPE

} AUX_TYPE;

typedef enum
{
  FAST_OVEN = 0, REG_OVEN = 1

} OVEN_TYPE;

#define DET_UNITS_LABEL_SIZE 11

/* host_model entries follow ... */
#define TYPE_13_14_AS_AIB   0
#define TYPE_13_14_AS_NODET 1
#define TYPE_13_14_AS_IS    2

typedef struct
{
   DET_TYPE type;
   DET_TYPE old_type;
   BIT8     old_cpf;
   BIT8     electrometer;    /* Used for FID & FPD only:
                                   0 = false
                                   otherwise - disable flame ignition and
                                     pnuematics module presence requirement */

   BIT8     units_label[DET_UNITS_LABEL_SIZE];
   BIT8     title[7];
   BIT8     host_model;

} DET_CONFIG;

typedef enum
{
        US              = 0,
        GERMANY         = 1,
        BRAZIL          = 2,
        CHINA           = 3,
        INDIA           = 4,
        JAPAN           = 5,
        UNKNOWN_COUNTRY = 6
} COUNTRY;


typedef struct
{
        COUNTRY  country;
        U_INT32  number;
} SERIAL_NO;


typedef struct
{
        U_INT8     year;
        U_INT8     month;
        U_INT8     day;
        U_INT8     hour;
        U_INT8     minute;
        U_INT8     second;
}  DATETIME;

typedef struct
{
        U_INT16    days;
        U_INT8     hours;
        U_INT8     minutes;
        U_INT8     seconds;
}  TIME;

/***** time table structure *****/

typedef struct tte {
                    INT32    Time;
                    INT32    Parm;
                    U_INT8   Type;

                  }  TIME_TABLE_ENTRY, *pTIME_TABLE_ENTRY;


#define NUM_TIME_TABLE_ENTRIES 26
#define NUM_AVAIL_ENTRIES (NUM_TIME_TABLE_ENTRIES -1)

typedef struct {    TIME_TABLE_ENTRY    Table[ NUM_TIME_TABLE_ENTRIES ];
                    U_INT8              Current_Entry_Index;

   /* the current entry index is really part of 'status' not wkfile. */
   /* it is maintained here to keep the table and it's parts together */

               } TIME_TABLE, *pTIME_TABLE;


/* revisit, the 300 psi sensor is the one used only for manny */
/*          the 15 psi sensor should really be 0              */
/*  these values are sent directly to the pcb and need to     */
/*  match the pcb definition                                  */

typedef enum { N2=0,  H2=1,  He=2,  ArMe=3, O2=4, Air=5,  Argon=6, UNKNOWN_GAS=7 } GAS_TYPE;

typedef enum {CONST_PRES, CONST_FLOW, RAMP_PRES, RAMP_FLOW, UNKN } CONTROL_MODE;

typedef enum { FRNT_INLET     = 0,   /* Keep same numbers as */
               BACK_INLET     = 1,   /* VALVE_POSITION below */
               AUX_3          = 2,
               AUX_4          = 3,
               AUX_5          = 4,
               UNKNOWN_SOURCE = 5
             } SOURCE_CONNECTION;

typedef enum { PSI_15=3,    PSI_100=1,   PSI_200=0, PSI_300=2, NoPSensor=4 } P_SENSOR_RANGE;

typedef enum { FRNT_DET,    BACK_DET,    MSD,   AED,   UNKNOWN_OUTLET      } OUTLET_CONNECTION;
typedef enum { SCCM_200_N2, SCCM_700_N2, NoFSensor           } F_SENSOR_RANGE;

typedef enum { DISPLAY_PSI = 0,
               DISPLAY_BAR = 1,
               DISPLAY_KPA = 2
             } PRES_UNITS;
/*

typedef enum { SPLIT  , SPLITLESS  , SPLITLESS_PULSED  , SPLIT_PULSED  , SOLVENT_VENT } INJ_MODE;

INJ_MODE was originally coded as above . This is fragile b/c array addressing in pneu_tbls.c ASSUMES that the above
assignments that implicity fell out of the above will not chg .  If any of these symbols end up with different values then
arrays Sc_Cmd_Table, GPTV_Cmd_Table, VI_Cmd_Table & any future arrays in pneu_tbls.c must be revised along with the
wrapper fns for these arrays.

*/

typedef enum { SPLIT=0, SPLITLESS=1, SPLITLESS_PULSED=2, SPLIT_PULSED=3, SOLVENT_VENT=4, avail1=5, DIRECT=6 } INJ_MODE;

typedef enum { False=0,     True=1       } TRUE_FALSE;


/* Valves:         */

   /* fix valve type values for command set */
   typedef enum
   {
      NO_VALVE        = 0,
      MULTIPOSITION   = 1,
      GAS_SAMPLING    = 2,
      SELECTION       = 3,   /* same as switching */
      OTHER           = 4,
      REMOTE_START    = 5    /* only allowed on 7 or 8 contact closures */
                             /* EOS uses 6 as NOT_IMPLEMENTED           */

   } VALVE_TYPE;

   typedef enum
   {                         /* NOTE: Keep these the same as the SOURCE_CONNECTION */
      NO_CONNECTION  = 5,    /* typedef above.  Both Rick & Tom have been hosed by */
      FRONT_INJ      = 0,    /* typing AUX3 when we wanted AUX_3 or vice versa.    */
      BACK_INJ       = 1,    /* The real fix would be to eliminate VALVE_POSITION  */
      AUX3           = 2,    /* and just use SOURCE_CONNECTION.                    */
      AUX4           = 3,
      AUX5           = 4
   } VALVE_POSITION;

   typedef struct
   {
      VALVE_TYPE     type;
      VALVE_POSITION position;
      U_INT16        loop_volume;
   } VALVE_CONFIG, *pVALVE_CONFIG;


/* Keyboard & Display typedefs */

typedef   BIT8       LINE[64];
#define   POSN       61
#define   INDX       62


/*--------begin change by wangwei----------*/
/*
typedef  struct
         {
            BIT8     lock_byte;
            BIT8     filler_for_alignment;
            U_INT32  locker_addr;
         } RESOURCE, *pRESOURCE;
*/
typedef pthread_mutex_t RESOURCE;
typedef pthread_mutex_t* pRESOURCE; 
/*--------end change----------------------*/


  /* invalid ramp is used for initialization purposes only. */
  /* it does not modify the behavior on the ramp generator. */
typedef enum { INVALID_RAMP, THERMAL_RAMP, PRESSURE_RAMP, FLOW_RAMP } RAMP_TYPE;


/* Constants used by the ramp generator */

#define RAMP_LEVELS          3
#define DET_RAMP_LEVELS     10
#define OVEN_RAMP_LEVELS     6

/* Structures used by the ramp generator */

typedef struct
{
  U_INT32 rate;
  U_INT32 final_value;
    INT32 final_time;
} RAMPS;

typedef struct
{
    INT32 init_time;
  U_INT32 init_value;
  /* the ramp array exists as a separate item */
  U_INT32 post_value;
  RAMP_TYPE ramp_type;
} RAMPTBL;

typedef union
{
   BIT8 byte[4];
   U_INT32 value;
} IP_ADDRESS_TYPE;

/* CPF definitions */
/* EEPROM Thermal config definitions */

#define NO_MINSTPT      -210
#define NO_MAXRATE       -1
#define NO_MINCTLERR      0

/* Offsets used by zone configuration to obtain the enumerated value, where */
/* 0 = undefined.                                                           */

#define CFR_OFST   1       /* control_freq:        CONTROL_FREQ+1 */
#define CCT_OFST   1       /* cryo_control_type:   CRYO_CONTROL+1 */
#define INP_OFST   1       /* max/min_integ_power: INTEG_CLAMP+1  */
#define SNR_OFST   1       /* sensor_type:         TEMP_SENSOR+1  */
#define RMP_OFST   1       /* ramp_comp:           RAMP_COMP+1    */


/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/

#define UNKNOWN 2

#define TRUE    1
#define FALSE   0

/* Scale factor tags for pressure & pressure ramp commands */
#define P_SCALE 255
#define R_SCALE 254


/* used to eliminate support for partially implemented phase 2 features */

#define VOLATILES_SUPPORT
#define CIS4_SUPPORT

/*****************************/
/*   SECTION MAP             */
/*****************************/

#ifndef mccabe
#pragma ASM
        SECTION                 mfstart,2,D,D   ;Manufacturing start word
        SECTION                 manuf,2,D,D     ;Manuf data (serial#, manuf date, etc.)
        SECTION                 mfend,2,D,D     ;Manuf data end word
        SECTION                 pfstart,2,D,D   ;Power fail start word
        SECTION                 pfail,2,D,D     ;Power fail protected data
        SECTION                 pfend,2,D,D     ;Power fail end word
        SECTION                 SysData,2,D,D   ;OpSys Data
        SECTION                 rampool,2,D,D   ;NewtOS memory manager heap
        SECTION                 methpool,2,D,D  ;method storage heap
        SECTION                 DRam,2,D,D      ;Dynamic RAM

        SECTION                 boot,2,C,P      ;Boot code through checksum
        SECTION                 rom3,2,C,P      ;(was) code for 3rd 256k ROM
        SECTION                 keybd,2,C,P     ;Keyboard code
        SECTION                 flow1,2,C,P     ;flow tables
        SECTION                 flow2,2,C,P     ;flow tables
        SECTION                 flow3,2,C,P     ;flow tables
        SECTION                 const,2,C,P     ;tables
        SECTION.S               SysCode,2,C,P   ;Opsys & Interrupt Code
#pragma END_ASM
#endif

#endif  /* #ifndef TYPEDEFS_H */
